package com.atguigu.gmall.common.util;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lfy
 * @Description
 * @create 2023-07-29 16:21
 */
public class HttpUtil {

    public static HttpServletRequest currentRequest(){
        //如果是异步。且没有共享老请求，这个 attributes 就是null
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        if(attributes!=null) return attributes.getRequest();
        return null;
    }
}
